#include <Timer.h>
#include <UserButton.h>
#include "MainAppC.h"
#include "printf.h"


module MainAppC {
	uses interface Boot;
	uses interface Notify<button_state_t> as Button;
	uses interface LEDControl;	
	uses interface SendControl;
	uses interface Data;
}
implementation 
{
	uint8_t mode = Passive;
	
			
	event void Boot.booted() {
		call Button.enable();
		call SendControl.start();
	}
	

	event void Button.notify(button_state_t state) {
		if(state == BUTTON_PRESSED) 
		{			
			switch(mode)
			{
				case Passive:
					mode = Receive;
					break;
				
				case Receive:
					mode = Send;
					break;
					
				case Send:
					mode = Passive;
					break;
				
				default:
					mode = Passive;
					break;
			}
			
			switch(mode)
			{
				case Passive:
					call LEDControl.On(LEDState_ModePassive);
					call SendControl.stopTransmitting();
					break;
				
				case Receive:
					call LEDControl.On(LEDState_ModeReceive);
					break;
					
				case Send:
					call LEDControl.On(LEDState_ModeSend);
					call SendControl.startTransmitting();
					break;
				
				default:
					call LEDControl.On(LEDState_ModePassive);
					call SendControl.stopTransmitting();
					break;
			}
		}
		else 
			if(state == BUTTON_RELEASED) 
			{				
				call LEDControl.Off(LEDState_AllOff);
			}
	}

}